home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
basic
/
Crazy8.src.lha
/
Scource
/
Crazy2.8.asc
< prev
next >
Wrap
Text File
|
1999-02-01
|
62KB
|
2,096 lines
; Crazy 8's
; Ver 2.8
; by Curt Esser
; 113 Pauline Ave
; Crystal Lake
; Il. 60014
; camge@ix.netcom.com
; last modified 1/28/98
WBStartup ;run from WorkBench!
v$="$VER: Crazy8 v2.8 (28-01-99) by Curt Esser"
ScreenPens 1,4,0,3,7,3,3
If NTSC=True
vrate=60 ;adjust for NTSC or PAL Vblank rate
Else
vrate=50
EndIf
;---------------------------------------------------------------
ourpath$=ProgDir$ ;get our program's directory
;----------------------------------------------------------------
; fade the current screen to a new palette
Statement fadeto{palobj,speed} ;speed must be 1+
PaletteInfo palobj
For i = 0 To 15 ;number of available colour steps
For j=0 To 7 ;number of currently used colours
rd = Red(j)
If rd < PalRed(j) Then rd+1 ;check each for the difference
If rd > PalRed(j) Then rd-1 ;between current colour and
bl = Blue(j) ;the target colour
If bl < PalBlue(j) Then bl+1 ;and reset as needed
If bl > PalBlue(j) Then bl-1
gr = Green(j)
If gr < PalGreen(j) Then gr+1
If gr > PalGreen(j) Then gr-1
RGB j,rd,gr,bl ;and reset current screen
Next j
VWait speed ;take out if too slow or
Next i ;increase if too fast
End Statement
;----------------------------------------------------------------
ntsSys=NTSC ;True if a NTSC system
Forced.b=0 ;if display was forced
;Some constants for use when setting FNSPrefs
#none=0
#centred=%1
#bold=%10
#underline=%100
#rightalign=%1000
;Install our font as number 1
#font=1
suc.l=InstallFNS(#font,?font_dat)
;suc.l=FNSLoad("Windy.FNS",#font)
;If suc.l doesn't equal #font then an error occured
If suc<>#font Then Request Str$(suc),"Can't Load Font","Damn" : End
;-----------------------------------------------------------------
wb.w=WBWidth ;how wide is user's screen?
If wb>720 Then wb=720 ;check for oversized bench
wb=Int(wb/2) ;divide for our lo-res screen
ofst.b=Int((wb - 320)/2) ;and get horizontal to center it
.Loadup
MaxLen newmod$=192 ;for selecting new module
MaxLen fi$=255 ;filename $
MaxLen pa$=255 ;mod path $
MaxLen snd$=255 ;sounds path $
MaxLen newsnd$=255
BitMap 0,320,200,3 ;lo-res 8 colors page
BitMap 1,320,200,3 ;double buffered drawing page
InitPalette 0,8 ;set a palette to black
Screen 0,ofst,0,320,200,3,0," Crazy 8's 2.7",0,0,0 ;open the screen
Use Palette 0 ;black screen to start
Window 0,0,0,320,200,$1900," ",0,0 ;open our window
ShowBitMap 1 ;show blank page
MenusOff ;we use no menus
CatchDosErrs ;show system requestors on our screen
LoadBitMap 0,"data/C8.Title",0 ;load the title screen pic
SetCycle 0,0,2,5,.25 ;set up for color cycling
ShowBitMap 0 ;get title screen ready
Cycle 0 ;make letters on title "squirm"
fadeto{0,2} ;and fade in the title screen
Dim txt$(74) ;for text from locale file C8.LOCALE
Gosub GetLocale ;load up the locale file
Gosub loadpref ;and the prefs file
hold.w=0 ;used for message delay
Use BitMap 0
LoadBitMap 1,"data/C8.playscreen",1 ;load game screen & palette
LoadPalette 2,"data/pal.pref" ;load palette for options page
LoadPalette 3,"data/pal.x" ;load all grey palette for fades
LoadPalette 4,"data/pal.green" ;load the other screen palettes
LoadPalette 5,"data/pal.grey" ;for player to switch to
LoadPalette 6,"data/pal.tan"
LoadPalette 7,"data/pal.maroon"
LoadPalette 8,"data/pal.purp"
LoadPalette 9,"data/pal.purp2"
LoadPalette 10,"data/pal.yelo"
LoadPalette pl.b,"data/pal.pointer",16 ;load colors for the pointers
Dim sd$(33) ;for the 34 sounds
Dim Timeout.w(33) ;and their mask time
For i=0 To 33 ;read them from data $
Read sd$(i)
Next
;Names for the sounds:
Data$ "Laugh","aarrgghh!","awwww","NotCompute","clap"
Data$ "drum","GameOver","scream","Shuffle","snare"
Data$ "tankoo","uh-oh","spoit","tick","bell"
Data$ "Cuckoo","Hey1","boom","Whoosh","BowArrow"
Data$ "Cut.it.out","Girl.sigh","Glepuughn","Oooh","DaMeaning"
Data$ "Spit","Yeah","Drip1","WhatDo","Carumba"
Data$ "doh01","doh30","doh31","excellent"
Gosub LoadSounds
If Peek.l(Addr Sound(0)) ;make sure it's there!
Sound 0,1 ;play the crazy laugh
VWait 12 ;and echo it in
Sound 0,2 ;the other speaker
EndIf
SetErr
ShowBitMap 0 ;make sure we're on the right bitmap
Use BitMap 0 ;and put up a requestor
Request txt$(60),txt$(62),txt$(61)
StopMed
Quiet 15
End ;and end program
End SetErr ;that wasn't so hard!
LoadShapes 0,"data/card.shapes" ;0=back 1-52 cards s/h/c/d
LoadShapes 53,"data/newgad.shapes" ;53=SetUp,exit,Play/54-57 cardflips
;58 suit select/59 8 <-
;60-63 s/h/c/d ;64 Quit Requestor
LoadShapes 65,"data/pointer.shps" ;65-67, normal,btn dwn,wait pointers
Use BitMap 1 ;use the unseen page
Boxf 16,110,40,142,6 ;draw a "blank" shape
GetaShape 68,16,110,24,32 ;pick it up for erasing
MidHandle 68 ;and set its handle to center
Boxf 16,110,40,142,0
Use BitMap 0 ;now use the title page
If ModOn.b=1 ;Load music mod if wanted
ld$=pa$+"/"+fi$ ;make loading $
LoadMedModule 0,ld$ ;load the music
music=1 ;set the music on flag
Else ;if no module is to be loaded
music=0 ;make sure the flag is off!
EndIf
VWait 120 ;wait for the laugh to end
Gosub MusicOn ;start music & set filter
;======================================================================
SetInt 5 ;countdown the timer
If hold.w ;and play the music
hold-1
EndIf
If music=1 ;only if the music is on
If hold=1 Then SetMedMask 15 ;if the sound is done, use all 4
PlayMed ;now play the next beat of music
End If
End SetInt
;======================================================================
.Initialize
Dim Deck.b(52) ;Deck of Cards
Dim Pile.b(52) ;Discard Pile
Dim Phand.b(52) ;Player's Hand ( Card# )
Dim Ppos.w(52,1) ;Player Card Positions (x,y)
Dim Chand.b(52,3) ;Computer's Hand (Card,playability,suit,rank)
Dim scorename$(30)
Dim gamesplayed(30)
Dim gameswon(30)
Dim winpct.w(30)
NEWTYPE.scores ;for the listviews
pad.w
string.s
End NEWTYPE
Dim List sndDrawers.scores(50)
complain.b=1 ;computer's complaints
Split.b=0 ;end game flag
Pscore.w=0 ;Player's Score
Cscore.w=0 ;Computer Score
Pcards.b=0 ;Cards in Player's Hand
Ccards.b=0 ;Cards in Computer Hand
Cspades.b=0 ;number of cards in each suit in
Chearts.b=0 ; computer's hand
Cclubs.b=0
Cdiamonds.b=0
Cmost.b=0 ;suit computer has most of
Compeight.b=0 ;how many 8's computer has
mxx.b=0 ;maximum cards of any suit
PlayCard.b=0 ;Card selected for play
Inhand.b=0 ;Position in player's hand
Suit.b=0 ;Suit of selected card
Rank.b=0 ;Rank of card selected (A - K)
CSuit.b=0 ;Current suit (s/h/c/d)
CRank.b=0 ;Current rank of card (A - K)
Dcards.b=52 ;Cards left in deck
Dpile.b=0 ;Cards in discard pile
card.b=0 ;Current Card
sx.w=0 ;shape drawing x
sy.w=0 ;shape drawing y
cx.w=16 ;comp. card x
cy.w=40 ;comp. card y
dx.w=0 ;destination x
dy.w=0 ;destination y
sortflag.b=0 ;is player's hand sorted?
rd.w=0 ;colors for fading
bl.w=0
gr.w=0
flip.b=0 ;for turning cards over
flipfrom.b=0
flipto.b=0
up.b=1
down.b=-1
comppull.b=0 ;number of cards computer picked up
compflag.b=0 ;computer's turn
playerflag.b=0 ;player's turn
pickup.b=0 ;number of cards player picked up
Message$=txt$(0) ;"Written in Blitz"
see.b=0 ;bitmap being viewed
draw.b=0 ;bitmap being drawn on
temp.b=0 ;temporary storage
temp2.b=0
temp3.b=0
paltemp.w=0
ok.b=0 ;is card ok to play?
shp.b=0 ;shape # to be drawn
btn.b=0 ;1=left 2=right mouse button clicked
mx.w=0 ;mouse x position
my.w=0 ;mouse y position
chx.w=0 ;check x
chy.w=0 ;check y
hit.b=0 ;item that was clicked on
check.b=0 ;item being checked
Row.b=1 ;Row selected card is in
Rowflag.b=1 ;Number of rows in players hand
setup.b=0 ;1 if game was already played
replay.b=0
sleep.b=0 ;program is sleeping but start music if = 1 on return
defpa$="data/mods" ;default path for music module
deffi$="med.moonshine" ;default mod name
Message$="by Curt Esser"
Buffer 0,8192 ;set up drawing buffers
Buffer 1,8192 ;for each drawing page
For i = 1 To 52 ;set up the "deck" of cards
Deck(i)=i
Next
px.w=15 ;preset positions for
py.w=128 ;all 50 cards to go
For i = 1 To 50 ;in the player's hand
If i=26 ;in two horizontal
px=15 ;rows
py=162
EndIf
Ppos(i,0)=px ;and store them in
Ppos(i,1)=py ;an array
px+12
Next
draw=1 ;draw on page one
Gosub PrintReq ;draw localized text onto the "requestors"
.StartScreen ;now we are ready to go
ShowBitMap 0 ;needed to be sure we are on the right
Use BitMap 0 ;bitmap if game was played before
StopCycle ;stop the title from flashing
Use Palette pl.b ;and reset the palette
WPointer 65 ;show the normal game pointer
;InitPalette 0,8 ;make palette 8 black for fading
For i = 0 To 7 ;set palette 0 to all black again
PalRGB 0,i,0,0,0;for final fade-out
Next
.StartSc2
Blit 53,160,139 ;show the "SetUp Exit Play" Requestor
noise=12
Gosub makenoise ;make sure the player is awake
Prequest ;wait for player to select option
Gosub getmouse
If RectsHit(mx,my,1,1,38,109,44,60) Then Goto Prefs ;Options
If RectsHit(mx,my,1,1,238,109,44,60) Then Goto Playgame ;Play
If RectsHit(mx,my,1,1,149,124,22,30) ;Quit
Gosub MenU ;make sure it's not a mistake
If Split=1 Then Goto split ;confirmed, so quit game
EndIf
Goto Prequest ;cancelled quit, so try again
.MenU ;See what they want
If setup=1 ;We're on gamescreen
Message$="????"
Use BitMap draw
Gosub PrintMessage
Else
VWait 30 ;make sure player sees requestor
EndIf
Split=0 ;default is don't quit
noise=2:Gosub makenoise
shp=64:sx=160:sy=139 ;show the "button menu"
Use BitMap see
BBlit see,shp,sx,sy ;on the viewed page
selection.b=0
tpl=pl
Repeat
Gosub getmouse ;wait for the response
If mx>19 AND mx<303 AND my>117 AND my<162
If mx>19 AND mx<67
selection=1 ;CONTINUE
noise = 33
Gosub makenoise
EndIf
; Button Menu Options:
If mx>65 AND mx<114 ;Show Score Table
noise=30
Gosub makenoise
Gosub ScoreTable
;Request "","Score Table here","OK"
EndIf
If mx>113 AND mx<152 ;Change Palette
noise=13
Gosub makenoise
pl+1
If pl=2 OR pl=3 Then pl=4
If pl>10 Then pl=1
fadeto{pl,2}
EndIf
If mx>150 AND mx<206 ;Sounds
noise=24
Gosub makenoise
Gosub getSoundPath
If newsnd$<>snd$ AND newsnd$<>""
snd$=newsnd$
showerr.b=True
Gosub LoadSounds
EndIf
EndIf
If mx>205 AND mx<252 ;Music
noise=29
Gosub makenoise
Gosub LoadMed
EndIf
If mx>251 ;EXIT
selection=2
noise=4
Gosub makenoise
EndIf
Else
noise=3 ;bad selection
Gosub makenoise
EndIf
Until selection >0
If selection=2
Split=1
;Else
; VWait 60 ;hold on a second!
EndIf
UnBuffer see ;remove requestor from the screen
FlushBuffer see ;and from the buffer too
Use BitMap draw ;go back to unseen page to draw
If Split=0 AND setup=1
Message$=txt$(2)
Gosub PrintMessage
EndIf
Return
.split ;exit game
Message$=txt$(3)
If setup=1 Then Gosub PrintMessage
noise=6:Gosub makenoise
Gosub FinishSound
Gosub fademusic ;turn music off
Free MedModule 0 ;and release the mod's memory
split2
noise=19:Gosub makenoise
fadeto{0,3} ;fade to black
noise=17:Gosub makenoise ;a last audio "shot"
If Forced >0 ;fix screenmode if it was forced
Gosub FixMode
EndIf
Gosub FinishSound
Quiet 15 ;can the sound channels
End ;We're history
.Playgame ;finally, we can play the game!
WPointer 67 ;show wait pointer
gamedone.b=False
replay=0
Use BitMap draw ;make sure we are using the unseen page
Format "###" ;set the format for the score table
a$=txt$(4)
Boxf 180,62,210,72,3 ;Erase any old text first
Boxf 108,73,176,99,3 ;and any old names
FNSOutput draw,1 ;print on the unseen page
FNSPrint 1,113,63,a$,0,1 ;print the black shadows first
FNSPrint 1,113,63,a$,0,1
FNSPrint 1,112,63,a$,0,1
FNSPrint 1,112,62,a$,0,7 ;and now the gold text
a$=Str$(maxpoints.w)
FNSPrint 0,203,65,a$,#rightalign,1 ;print the numbers shadows first
FNSPrint 0,203,64,a$,#rightalign,1
FNSPrint 0,202,65,a$,#rightalign,1
FNSPrint 0,202,64,a$,#rightalign,7 ;and now the gold text
FNSPrint 1,109,76,compname$,0,1 ;print computer's name
FNSPrint 1,109,75,compname$,0,1 ;with shadows too
FNSPrint 1,108,76,compname$,0,1
FNSPrint 1,108,75,compname$,0,7
FNSPrint 1,109,89,playername$,0,1 ;and player's name
FNSPrint 1,109,88,playername$,0,1 ;the same way
FNSPrint 1,108,89,playername$,0,1
FNSPrint 1,108,88,playername$,0,7
Blit 0,232,82 ;the deck
Gosub Newpage ;switch pages
CopyBitMap see,draw ;and make both pages look the same
fadeto{pl,1} ;and fade in the screen
If setup=0 ;this is the very first game
noise=12:Gosub makenoise ;so make a noise!
VWait 30
EndIf
FlushEvents
.Newhand ;set up for new hand
Gosub showscore ;update the score
Gosub showCcards
If setup=1 ;if it's not the first game
Message$=txt$(5)
EndIf
setup=1 ;once we get here set the flag
Gosub PrintMessage ;and print the appropriate message
Dcards=52:Pcards=0:Ccards=0:Dpile=0:compflag=0:playerflag=0
For i=1 To 52 ;set up new deck of cards
Deck(i)=i ;in order to start with
Next
Gosub Shuffle ;and shuffle them
VWait 30
Gosub Shuffle ;twice
For d=1 To 5 ;deal 5 cards to each player
Gosub Compget ;one to each
Gosub showCcards
Gosub Playerget ;in order
Next
Upcard ;turn next card up to start game
Gosub Grabcard ;get the card
Repeat
sx-4 ;and slide it over
Gosub Draw
Until sx=88 ;into position
flip=up
Gosub Flipit ;now flip it over
Dpile+1 ;and keep track of what's
Pile(Dpile)=card ;in the pile
Gosub WhatCard ;now convert it from a number
CSuit=Suit ;to the Current Suit
CRank=Rank ;and Current Rank
Gosub Sorthand ;sort the player's hand
If music=1 Then Gosub MusicOn ;and start the music if it's on
VWait
noise=27 ;let user know
Gosub makenoise ;we're ready to play
;-------------------------------------------------------------------
; MAIN GAME LOOP
;-------------------------------------------------------------------
.GameLoop
pickup=0 ;nothing has been picked up yet!
Message$=txt$(6)
If Ccards=1 Then Message$=txt$(7)
Gosub PrintMessage
.PlayerTurn
playerflag=1 ;human's turn
ok=0
Gosub getmouse ;wait for input
CopyBitMap see,draw ;make sure both pages are the same
ShowBitMap 0
Use BitMap 1
see=0
draw=1
If hit=0
Gosub HitWhat ;OK, what happened?
EndIf
Select hit ;now deal with the selection
Case 1 ;clicked deck
Gosub Playerget ;pick up a card from the deck
pickup+1 ;count how many cards are picked up this turn
Case 2 ;player clicked MENU
Gosub MenU ;so deal with it
Case 3 ;player clicked a card
card=PlayCard ;ok we'll try to play it
Gosub WhatCard ;check if it's a legal play
If ok=1 ;it is so let user play it
If card=Phand(Pcards) ;this card was just picked up
pickup-1 ;so take it off the count
EndIf ;and maybe we won't need to sort hand
noise=5:Gosub makenoise
Gosub Pullcard ;pull it out
Gosub Playcard ;and play it
noise=13:Gosub makenoise
If Row<>Rowflag Then Gosub MoveUp ;if two rows move one card up
For i=Inhand To Pcards ;this stuff moves the cards
Phand(i)=Phand(i+1) ;over to correct the array
Next ;for the card we took out
Pcards-1:playerflag=0 ;and correct the count
If CRank=8 Then Gosub SetSuit ;choose suit if an 8 played
Else ;go here if the card
noise=3 ;is not a legal play
Gosub makenoise ;let the user know about it
EndIf ;and do nothing else
Case 4 ;clicked SORT
If Pcards=1 OR Sortflag=1 ;no need to sort
noise=16 ;so we'll make
Gosub makenoise ;a sound instead
VWait 10 ;in fact, let's make
Gosub makenoise ;it echo too!
Else
Gosub Sorthand ;ok, we'll sort the hand
EndIf
Case 5 ;player clicked hide
sleep=2 ;so set the sleep flag
If music=1
sleep=1 ;make it 1 to restart music later
music=0 ;but turn it off now
StopMed
End If
VWait 2
If Forced>0
Gosub FixMode
EndIf
WBenchToFront_ ;and bring up WorkBench
ClickButton 0 ;and activate it
FlushEvents
hit=0
Pop Select
Goto PlayerTurn
Default ;player has clicked something else
noise=3 ;but there IS nothing else!
Gosub makenoise ;let 'em know they made a mistake
End Select
hit=0
VWait
If Split=1 Then Goto split ;user wants to quit so do it
If Pcards=0 ;player has won hand!
playerflag=1 ;so set the flag
Goto Handover ;and end this hand
EndIf
If Dcards=0 Then Gosub Reshuffle ;no cards left - use discards
If playerflag=1 Then Goto PlayerTurn ;still player's turn
If Sortflag=0 AND pickup>0 Then Gosub Sorthand ;if necessary
holdit.b=2 ;computer's turn now
Message$=txt$(8) ;so greet the player
WPointer 67 ;and put up wait pointer
comppull=0 ;and reset pickup count
If Pcards=2 AND Ccards>2 ;player only has 2 cards
Gosub CompNoise ;and we have more so we complain
Select complain ;set a new complaint
Case 1
Message$=txt$(9)
Case 2
Message$=txt$(10)
Case 3
Message$=txt$(11)
Case 4
Message$=txt$(12)
Case 5
Message$=txt$(13)
Case 6
Message$=txt$(14)
Case 7
Message$=txt$(15)
Case 8
Message$=txt$(16)
Case 9
Message$=txt$(17)
End Select
Gosub CompComplain
EndIf
If Pcards=1 ;now the player only has one card
Gosub CompNoise
Select complain ;so REALLY whine about it
Case 1
Message$=txt$(18)
noise=20
Case 2
Message$=txt$(19)
Case 3
Message$=txt$(20)
Case 4
Message$=txt$(21)
Case 5
Message$=txt$(22)
Case 6
Message$=txt$(23)
Case 7
Message$=txt$(24)
Case 8
Message$=txt$(25)
noise=22
Case 9
Message$=txt$(26)
End Select
Gosub CompComplain
EndIf
WildHair.b=0
If CRank=8 AND Pcards=1 AND Rnd(10)>4
WildHair=1
pullet.b=Rnd(8)+6
EndIf
.Computerturn
; Chand.b(52,3) ;Computer's Hand (Card,playability,suit,rank)
Gosub PrintMessage ;let 'em know it's our turn now
Gosub FinishSound
ok=0:cplay.b=0:compflag=1:Cspades=0:Chearts=0:Cclubs=0
Cdiamonds=0 ;reset everything for this turn
For i=1 To Ccards
card=Chand(i,0) ;this part checks
Gosub WhatCard ;the computer's hand
If Suit=0 AND Rank<>8 Then Cspades+1 ;for the number of
If Suit=1 AND Rank<>8 Then Chearts+1 ;cards of each suit
If Suit=2 AND Rank<>8 Then Cclubs+1 ;so we know what suit to
If Suit=3 AND Rank<>8 Then Cdiamonds+1 ;pick if we play an 8
mxx=Cspades:Cmost=0 ;this stuff
If Ccards=1 ;finds out which suit we have
mxx=1 ;the most of so we can pick it
If Chearts=1 Then Cmost=1 ;if we played an 8
If Cclubs=1 Then Cmost=2 ;if 2 or more are equal, we'll
If Cdiamonds=1 Then Cmost=3 ;randomly pick one of them
Else
If Chearts>mxx OR (Chearts=mxx AND Rnd(2)>1)
Cmost=1
mxx=Chearts
EndIf
If Cclubs>mxx OR (Cclubs=mxx AND Rnd(2)>1)
Cmost=2
mxx=Cclubs
EndIf
If Cdiamonds>mxx OR (Cdiamonds=mxx AND Rnd(2)>1) Then Cmost=3
EndIf
Chand(i,1)=0 ;not playable
Chand(i,2)=Suit
Chand(i,3)=Rank
If ok=1
If Rank<>8 ;if the card is a legal play
Chand(i,1)=1
Else
Chand(i,1)=-1 ;8 flag
EndIf
EndIf
;If ok=1 AND (Pcards>1 OR Ccards=1 OR Rank=CRank) Then Chand(i,1)=1 ;card is a legal play
Next
For i = 1 To Ccards ;OK, now score play desirability
If Chand(i,1)>0 ;only on playable cards, of course!
If Chand(i,2)=Cmost
Chand(i,1)+1 ;have most of this suit!
EndIf
For j = 1 To Ccards
If j<>i AND Chand(j,1)<>-1
If Chand(i,3)=Chand(j,3) ;same Rank as another card in our hand!
Chand(i,1)+1
EndIf
EndIf
Next
EndIf
Next
Compeight=0
Best.b=1
For i=1 To Ccards
If Chand(i,1)=>Best
Best=Chand(i,1)
cplay=i ;ok, we will play this one
EndIf
If Chand(i,1)=-1
Compeight+1
EndIf
Next
If WildHair AND comppull<pullet Then cplay=0 ;try for an 8 to block a win
If (cplay=0 AND (Ccards<Compeight*2+1 OR Pcards<=Compeight OR Pcards=1)) OR Dcards<2 OR Ccards=Compeight ;OR Pcards<(Ccards/2
For i=1 To Ccards ;no non-8's to play
If Chand(i,1)=-1 Then cplay=i ;so play an 8 if we have one
Next ;unless we're way ahead
EndIf ;we'll save the 8 and draw
If Pcards>4 AND Ccards>2 AND cplay
If Rnd(30) > 28 Then cplay=0 ;just a bit of randomness to throw 'em off
EndIf
If cplay>0 ;we're going to play a card
If comppull=0 AND Ccards=1 ;if it's our last card
noise=10:Gosub makenoise ;let 'em know
Gosub FinishSound
EndIf
Gosub CompPlay ;play it!
Gosub Playcard ;alright, play it already!
If Rank=8 Then Gosub SetSuit ;ok an 8! Set our suit!
If Ccards=1 ;we only have one card
noise=11 ;left so warn the player
Gosub makenoise
End If
EndIf
If cplay=0 ;we're picking up too
If comppull>1 ;many un-playable cards
Gosub CompNoise
Select complain ;so moan about it!
Case 1
Message$=txt$(27)
Case 2
Message$=txt$(28)
Case 3
Message$=txt$(29)
Case 4
Message$=txt$(30)
Case 5
Message$=txt$(31)
Case 6
Message$=txt$(32)
Case 7
Message$=txt$(33)
Case 8
Message$=txt$(34)
Case 9
Message$=txt$(35)
End Select
Gosub CompComplain
Gosub PrintMessage
EndIf
VWait hold+15
Gosub Compget ;go get another card
comppull+1
EndIf
If Dcards=0 ;and re-shuffle the discards
Gosub Reshuffle ;if the deck is all used up
VWait 30
EndIf
Gosub showCcards
If cplay=0 AND Dcards>0 Then Goto Computerturn ;still Amiga's turn
If Ccards=0 Then Goto Handover ;we won this hand
compflag=0 ;we didn't win
Goto GameLoop ;so back to the player
.Handover ;ok, we managed to finish a hand
WPointer 67 ;put up the busy pointer
Gosub fademusic ;and can the music
If playerflag=0 ;computer won
noise=2 ;make appropriate noise
Gosub makenoise
Message$=txt$(36) ;and print a message
Gosub PrintMessage
Gosub FinishSound
Repeat
Inhand=Pcards:card=Phand(Inhand) ;now get the player's cards
Gosub Pullcard ;one at a time
Gosub Playcard ;& put 'em on discard pile
Gosub Score ;and score them
Pcards-1
Until Pcards=0 ;till we got 'em all
Else ;player won
Message$=txt$(37) ;say it in print
noise=0 ;and make a noise
Gosub makenoise ;now print the message
Gosub PrintMessage ;pause for a bit
Gosub FinishSound
Repeat ;now throw computer's cards
cplay=Ccards ;on the discard pile
Gosub CompPlay ;one at a time
Gosub Playcard
Gosub showCcards
Gosub Score ;and score each
Until Ccards=0 ;till they're all gone
EndIf
VWait 50
flip=down
Gosub Flipit ;turn the deck face down
VWait 20
For i=1 To 2 ;now erase the deck
Use BitMap draw ;off both screens
BlitMode EraseMode
Blit 68,sx,sy ;by drawing a blank card
BlitMode CookieMode
shp=0 ;but buffer-blit
Gosub Draw ;the card-back pic on both pages
Next ;so we can move it
noise=18
Gosub makenoise
Repeat ;now slide the discard pile back onto
sx+4 ;the main deck 4 pixels at a time
Gosub Draw
Until sx=232
Gosub Drawdone ;reset everything for the next time
If Cscore=>maxpoints OR Pscore=>maxpoints ;The game is over!
gamedone.b=True
noise=6
Gosub makenoise
If (Cscore=>maxpoints AND scoreon.b =0) OR (scoreon=1 AND Pscore =>maxpoints)
Message$=txt$(38) ;player won the game message
pwon.b=True
cwon.b=False
Else
Message$=txt$(39) ;computer won so print this one
pwon=False
cwon=True
EndIf
Gosub PrintMessage
Cscore=0 ;reset scores
Pscore=0
Gosub FinishSound
see=0
draw=1
ShowBitMap 0
Use BitMap 0
Gosub ScoreTable
replay=1 ;set the replay flag
Goto StartSc2 ;and go back to the beginning
EndIf
Goto Newhand ;game not over, play another hand
.Draw ;double buffer drawing routine
ShowBitMap see ;show the already-drawn page
VWait ;wait for the Vblank
Use BitMap draw ;now draw on the unseen page
UnBuffer draw ;erase the stuff we drew last time
BBlit draw,shp,sx,sy ;buffer-blit specified shape
Exchange see,draw ;make this the new viewing page
Return
Drawdone ;this part simply
ShowBitMap see ;resets both drawing pages
VWait ;so they are the same
CopyBitMap see,draw ;and clears out both buffers
FlushBuffer 0 ;so we are ready for the next
FlushBuffer 1 ;animation
Use BitMap draw
Return
Newpage ;this routine switches the
Exchange see,draw ;drawing (unseen) and
ShowBitMap see ;the veiwing (seen) pages
VWait ;so we don't have to do it
Use BitMap draw ;by hand all the time
Return
.Flipit ;this makes card flipping animation
flipfrom=54:flipto=57 ;flip shapes from face down to face up
If flip=down Then Exchange flipfrom,flipto ;do in reverse if needed
For i=flipfrom To flipto Step flip ;draw the shapes one
shp=i ;per frame till they
Gosub Draw ;are all done
VWait
Next
shp=card ;then draw actual card
If flip=down Then shp=0 ;or card back
Gosub Draw
noise=13
Gosub makenoise
Gosub Drawdone
Return
.Reshuffle ; reshuffles the discard pile
If Dpile=1 Then Return ; there's only one card - forget it!
For i=1 To Dpile-1 ; leave the top card out
Deck(i)=Pile(i) ; and set up our new deck using
Next ; the rest of the discards
sx=88:sy=82 ; now slide top card over
shp=Pile(Dpile)
Use BitMap draw
For i=1 To 2
Blit Pile(Dpile-1),sx,sy ;first we have to draw
BBlit draw,shp,sx,sy ;the next card down in the pile
Gosub Newpage ;on both pages under top card
Next ;because it will be seen soon
For i=1 To 12 ;now we slide the top card
sx-2 ;over to the left
Gosub Draw
Next
Gosub Drawdone
sx=88:sy=82:flip=down:Gosub Flipit ;now flip the "deck" down
For i=1 To 2 ;now we need to erase
BlitMode EraseMode
Blit 68,sx,sy ;both pages under the
BlitMode CookieMode
BBlit draw,shp,sx,sy ;"deck" pic
Gosub Newpage ;actually just 1 card back pic
Next
Repeat ;now we slide this over to the right
sx+6
Gosub Draw
Until sx=232 ;until it gets to the deck position
Gosub Drawdone
sx=64
shp=Pile(Dpile) ;now slide the top card back
BlitMode EraseMode
Blit 68,sx,sy ;where it was
BlitMode CookieMode
For i=1 To 2
BlitMode EraseMode
Blit 68,sx,sy
BlitMode CookieMode
BBlit draw,shp,sx,sy
Gosub Newpage
Next
For i=1 To 12
sx+2
Gosub Draw
Next
Gosub Drawdone
If CRank=8 ;and if it's an 8
Use BitMap see ;don't forget to draw the
Blit 60+CSuit,sx,sy ;selected suit back on it!
Use BitMap draw
Blit 60+CSuit,sx,sy
EndIf
Dcards=Dpile-1 ;now reset
Pile(1)=Pile(Dpile) ;the discard pile
Dpile=1
.Shuffle ;shuffle the deck
If Dcards=1 Then Return ;only one card - forget it!
WPointer 67 ;busy pointer
Blit 0,230,82 ;draw two card backs
Blit 0,234,82 ;offset from normal position
;but only on one page for animation
For q=1 To 4 ;shuffle them 4 times
For i=1 To Dcards ;re-arrainge deck
Exchange Deck(i),Deck(Rnd(Dcards)+1) ;at random by exchanging
Next ;card numbers
noise=8 ;now make shuffling
Gosub makenoise ;sound and
For i=1 To 20 ;animate by fliping the pages
ShowBitMap draw ;back and forth enough times
VWait ;to cover the length of the sound
ShowBitMap see
VWait ;the actual shuffling takes no time at all
Next ;this is all for show!
Next
Gosub Drawdone
Return
Grabcard ;pick up the top card on the deck
If Dcards<1 ;wait a minute! There's no more cards here!
card=-1 ;so set the flag
Return ;and leave
EndIf
card=Deck(Dcards) ;always take the top card
Dcards-1 ;and subtract one from the deck count
sx=232 ;set the starting position
sy=82 ;for the animation
shp=0 ;and set to card-back shape
If Dcards=0 ;and if this is the last card
Use BitMap draw ;erase the deck pic
For i=1 To 2 ;on both screens
BlitMode EraseMode
Blit 68,sx,sy
BlitMode CookieMode
BBlit draw,0,sx,sy ;but buffer-blit the one card back
Gosub Newpage
Next
EndIf
noise=18 ;ok, make a sound
Gosub makenoise
Return
.Compget ;pick up a card
Gosub Grabcard ;and send it to the computer's hand
Repeat
If sx>cx+4 Then sx-4 ;this stuff moves the
If sx>cx Then sx-1 ;card toward the next spot in
If sx<cx Then sx+2 ;the computer's hand and slows
If sy>cy Then sy-1 ;down when it gets close so we
shp=0 ;can hit the exact spot
Gosub Draw
Until sx=cx AND sy=cy
noise=13
Gosub makenoise ;make a sound when it gets there
Ccards+1 ;update the amount of cards
Chand(Ccards,0)=card ;and the computer array
cx+6 ;reset position for next card
Gosub Drawdone
Return
.Playerget ;player picks up a card
Gosub Grabcard ;get next card from deck
If card=-1 Then Return ;wait a minute-all cards GONE!
Pcards+1 ;add one to our count
Sortflag=0 ;and re-set the sort flag
Repeat
If sx>Ppos(Pcards,0)+4 Then sx-4 ;this slides the card
If sx>Ppos(Pcards,0) Then sx-1 ;into the player's hand
If sx<Ppos(Pcards,0)-4 Then sx+4 ;just like computer above
If sx<Ppos(Pcards,0) Then sx+1
If sy<Ppos(Pcards,1) Then sy+2
Gosub Draw
Until sx=Ppos(Pcards,0) AND sy=Ppos(Pcards,1)
Phand (Pcards)=card ;and update player's array
flip=up ;but we have to flip the player's
Gosub Flipit ;cards face up so we can see it
Return
.PrintMessage ;this prints message in message box
;on the draw page
FNSOutput draw,1
Boxf 4,185,314,196,3
FNSPrint 1,160,186,Message$,#centred,1
FNSPrint 1,160,185,Message$,#centred,1
FNSPrint 1,159,186,Message$,#centred,1
FNSPrint 1,159,185,Message$,#centred,7
; copy text from draw to see, 1 line at a time
For i = 184 To 197
addvaldraw.w=ADDValue(draw,0,i)
addvalsee.w=ADDValue(see,0,i)
Derez draw,see,addvaldraw,addvalsee,1,1
VWait
Next
Return
.getmouse ;wait for a mouseclick or keypress
WPointer 65 ;regular pointer
FlushEvents $8 ;clear any prior mouse events (for the trigger-happy user)
Repeat
ev.l=WaitEvent ;multi-task until response detected
Until EventWindow=0
If sleep >0 ;program was sleeping (screen hidden)
If sleep = 1 ;turn music on
If Forced=2 ;force screenmode if it was done before
ForcePAL
EndIf
If Forced=1
ForceNTSC
EndIf
music=1 ;fix the music flag
Gosub MusicOn ;and re-start it
sleep=0
FlushEvents
Goto getmouse
EndIf
EndIf
If ev=$400 ;key was pressed
t$=Inkey$
If t$=Chr$(27) ;ESC key
hit=2
Return
EndIf
If t$="p"
noise =4
Gosub makenoise
VWait
ForcePAL
Forced=2
EndIf
If t$="n"
noise=4
Gosub makenoise
VWait
ForceNTSC
Forced=1
EndIf
If t$="m" OR t$="M" ;user wants to toggle music off/on
If ModOn=1 ;we have loaded a mod
If music=1 ;so do it
Gosub fademusic ;but if off, do it gracefully
music=0
Else
music=1 ;was off, turn it on
Gosub MusicOn ;put a coin in the jukebox
End If
Else ;NO MOD IN MEMORY!!!
ShowBitMap 0
Request txt$(60),txt$(63),txt$(64)
ShowBitMap see
EndIf
End If
Goto getmouse ;go back & wait for mousebutton
End If
btn=1 ;left button down
If Joyb(0)=2 Then btn=2 ;right button
WPointer 66 ;show button down pointer
Gosub buttonUp ;wait till mousebutton is released
mx=WMouseX ;and get the
my=WMouseY ;pointer's position
FlushEvents ;again, save the trigger-happy
Return ;and continue the program
.buttonUp
Repeat ;now wait
ev.l=WaitEvent ;for mousebutton
Until ev=$8 AND Joyb(0)=0;till it is released
WPointer 65 ;use regular pointer
Return
HitWhat ;this determines what was clicked
hit=0 ;first we reset the flags
PlayCard=0
If RectsHit (mx,my,1,1,221,67,22,30) Then hit=1 ; draw a card
If RectsHit (mx,my,1,1,257,9,27,9) Then hit=2 ; menu button
If RectsHit (mx,my,1,1,225,9,27,9) Then hit=4 ; sort button
If RectsHit (mx,my,1,1,290,9,27,9) Then hit=5 ; hide bitton
If hit>0 Then Return ;Got it! we don't need to check for cards
check=1
If Pcards=1 Then Goto fullcheck ;only one card left!
checkcards ;checks all the visible card positions from left
If RectsHit (mx,my,1,1,Ppos(check,0)-11,Ppos(check,1)-15,11,30)
hit=3
PlayCard=Phand(check)
Inhand=check
EndIf
check+1
If PlayCard=0 AND check <Pcards Then Goto checkcards ;nope, try next
fullcheck ;the last card on right is bigger so we check full area
If RectsHit (mx,my,1,1,Ppos(check,0)-11,Ppos(check,1)-15,22,30)
hit=3
PlayCard=Phand(check)
Inhand=check
EndIf
Return
.WhatCard ;determine the suit & rank of a card from its number
Suit=0 ;set to first suit
Rank=card ;this is the card's number
checksuit
If Rank>13 ;only 13 cards per suit
Suit+1 ;so go to next suit
Rank-13 ;and subtract 13
Goto checksuit ;and try again
EndIf
ok=0 ;now reset flag
If Suit=CSuit OR Rank=CRank OR Rank=8 Then ok=1 ;and check for
Return ;playability
.Pullcard ;pull a card out of the player's hand
sx=Ppos(Inhand,0) ;get the drawing positions from
sy=Ppos(Inhand,1) ;the player position array
shp=card ;and set the drawing shape
Row=1:Rowflag=1:temp2=Pcards ;reset the flags to 1 row of cards
If Inhand>25 Then Row=2 ;card selected from second row
If Pcards>25 Then Rowflag=2 ;player has TWO rows of cards
If Row=1 AND Rowflag=2 Then temp2=25 ;but he selected from top row
For q=1 To 2 ;set up both pages
BlitMode EraseMode
Blit 68,sx,sy ;draw blank shape to erase
BlitMode CookieMode
If Inhand>1 AND Inhand<>26 Then Blit Phand(Inhand-1),Ppos(Inhand-1,0),Ppos(Inhand-1,1)
BBlit draw,shp,sx,sy ;and buffer blit the card
If Inhand<>Pcards AND Inhand <>25 ;if not last card in row
For j= Inhand+1 To temp2 ;re draw other cards to
Blit Phand(j),Ppos(j,0),Ppos(j,1);the right of selected one
Next
EndIf
Gosub Newpage ;and switch pages
Next q ;do the other page
If Inhand=Pcards OR Inhand=25 Then Goto ready ;if last card
For i=0 To 12 Step 2 ;otherwise, move cards to right
sy-5 ;over to fill the space
Gosub MoveEm
Next i
i=12
Gosub MoveEm
ready ;ok all done
ShowBitMap see
VWait
Use BitMap draw
Return
MoveEm
UnBuffer draw
BBlit draw,shp,sx,sy
BlitMode EraseMode
Blit 68,Ppos(temp2,0),Ppos(temp2,1)
BlitMode CookieMode
For j= Inhand+1 To temp2
Blit Phand(j),Ppos(j,0)-i,Ppos(j,1)
Next j
Gosub Newpage
Return
MoveUp
temp3=Inhand
Inhand=26
card=Phand(26)
Gosub Pullcard
Repeat
If sx<Ppos(25,0) Then sx+2
If sx<Ppos(25,0)-6 Then sx+4
If sx>200 AND sy<128 Then sy+1
If sy>128 Then sy-1
Gosub Draw
Until sy=128 AND sx=Ppos(25,0)
Gosub Drawdone
Inhand=temp3
Return
.CompPlay
cx-6:sx=cx:sy=cy:card=Chand(cplay,0)
For i=1 To 2
BlitMode EraseMode
Blit 68,sx,sy
BlitMode CookieMode
If Ccards>1 Then Blit 0,sx-6,sy
BBlit draw,0,sx,sy
Gosub Newpage
Next
flip=up
Gosub Flipit
For i=cplay To Ccards
Chand(i,0)=Chand(i+1,0)
Next
For i=1 To 2
BlitMode EraseMode
Blit 68,sx,sy
BlitMode CookieMode
If Ccards>1 Then Blit 0,sx-6,sy
BBlit draw,card,sx,sy
Gosub Newpage
Next
Ccards-1
Return
.SetSuit
If Pcards=0 OR Ccards=0 Then Return
If compflag=0 AND Sortflag=0 AND pickup>0 Then Gosub Sorthand
Message$=txt$(40) ;"O.K. Choose Your Suit"
If compflag=1
If WildHair
Message$="WildHair!"
Else
Message$=txt$(41) ;"Hmmmmm. Let's see!"
EndIf
EndIf
Gosub PrintMessage
noise=23:Gosub makenoise
ShowBitMap draw
VWait
Use BitMap draw
Blit 59,88,82
Blit 58,40,82
If compflag=1
If WildHair AND Cmost=CSuit
Cmost+1
If Cmost=4 Then Cmost=0
EndIf
Suit=Cmost
Message$=txt$(41)
VWait 150
Goto useit
EndIf
playerpick
Gosub getmouse
Suit=5
temp=8
For i=0 To 3
If RectsHit(mx,my,1,1,temp,71,14,15) Then Suit=i
temp+15
Next
If Suit=5
noise=3
Gosub makenoise
Goto playerpick
EndIf
Message$=txt$(43)
useit
Use BitMap see
Blit 60+Suit,88,82
CSuit=Suit
Gosub Drawdone
noise=5
Gosub makenoise
Gosub PrintMessage
;VWait 30
If compflag=1
noise=21
Else
noise=26
If Pcards<3 Then noise=33
EndIf
Gosub makenoise
VWait 100
Return
.Sorthand
Rowflag=1
If Pcards>25 Then Rowflag=2
card=Phand(Pcards)
sx=Ppos(Pcards,0)
sy=Ppos(Pcards,1)
dx=Ppos(1,0)
Gosub Slideleft
If Rowflag=2
sx=Ppos(25,0)
sy=Ppos(25,1)
card=Phand(25)
Gosub Slideleft
EndIf
For i= Pcards+1 To 52
Phand(i)=60
Next
Sort Phand()
card=Phand(Pcards)
sx=Ppos(1,0)
sy=Ppos(Pcards,1)
temp=1
temp2=Pcards
If Rowflag=2 Then temp=26
Gosub Slideright
If Rowflag=2
Rowflag=1
sx=Ppos(1,0)
sy=Ppos(1,1)
card=Phand(25)
temp=1
temp2=25
Gosub Slideright
EndIf
Sortflag=1
Return
Slideright
flip=up
Gosub Flipit
noise=18:Gosub makenoise
dx=Ppos(temp2,0)
If sx<>dx
Repeat
sx+4
For i=temp To temp2
If sx>Ppos(i,0) AND sx<Ppos(i,0)+20 Then Blit Phand(i),Ppos(i,0),Ppos(i,1)
Next
Blit card,sx,sy
Gosub Newpage
Until sx=dx
EndIf
Gosub Drawdone
Return
Slideleft
noise=18:Gosub makenoise
If sx<>dx
Repeat
BlitMode EraseMode
Blit 68,sx+3,sy
BlitMode CookieMode
sx-3
Blit card,sx,sy
Gosub Newpage
Until sx=dx
EndIf
Gosub Drawdone
flip=down
Gosub Flipit
Return
.Score
VWait 15
card=shp
Gosub WhatCard
If Rank>10 Then Rank=10
If Rank=1
Rank=20
noise=1+15*playerflag
Gosub makenoise
EndIf
If Rank=8
Rank=50
noise=7+3*playerflag
Gosub makenoise
EndIf
noise=14+playerflag
Gosub makenoise
If (playerflag=0 AND scoreon=0) OR (playerflag=1 AND scoreon=1)
Pscore=Pscore+Rank
Else
Cscore=Cscore+Rank
EndIf
showscore ;update the score box
Format "000" ;with three number format
BitMapOutput see ;just use the seen page
Colour 7,1 ;gold on black
Locate 23,9.9
Print Str$(Cscore) ;Computer's score
Locate 23,11
Print Str$(Pscore) ;Player's score
Gosub Drawdone
VWait 35
Return
.showCcards ;show computer cards in hand
Format "00" ;use two number format
BitMapOutput see ;use the seen page
Colour 7,1 ;gold on black
Locate 2,.8
Print Str$(Ccards) ;how many cards we're holding
BitMapOutput draw ;use the unseen page
Locate 2,.8
Print Str$(Ccards) ;how many cards we're holding
VWait hold+1 ;and make sure it's seen
Return
.Playcard
Repeat
If sx<84 Then sx+4
If sx<88 Then sx+1
If sx>92 Then sx-4
If sx>88 Then sx-1
If sy>85 Then sy-3
If sy>82 Then sy-1
If sy<80 Then sy+2
If sy<82 Then sy+1
Gosub Draw
Until sx=88 AND sy=82
Gosub Drawdone
Dpile+1
Pile(Dpile)=card
Gosub WhatCard
CSuit=Suit
CRank=Rank
Return
.Prefs ;Options window w/GT gadgets
t$=txt$(48)+"|"+txt$(49)
#ModString = 51
#BtnSave = 52
#ModReq = 54
#Music = 55
#SndFilter = 56
#LoseWinMX = 58
#ScoreMX = 59
#BtnUse = 60
#Pname = 61
#Cname = 62
GTString 0,#ModString,70,53,200,16,txt$(44),#PLACETEXT_LEFT,200,ld$
GTButton 0,#BtnSave,8,169,81,16,txt$(45),#PLACETEXT_IN
GTButton 0,#ModReq,270,53,19,16,"?",#PLACETEXT_IN
GTCheckBox 0,#Music,26,79,26,11,txt$(46),#PLACETEXT_RIGHT
GTCheckBox 0,#SndFilter,202,79,26,11,txt$(47),#PLACETEXT_RIGHT
GTMX 0,#LoseWinMX,46,116,17,9,"",#PLACETEXT_RIGHT,t$,scoreon.b
GTMX 0,#ScoreMX,208,113,17,9,"",#PLACETEXT_RIGHT," 50|100|150|200|300",scbtn.b
GTButton 0,#BtnUse,228,169,81,16,txt$(50),#PLACETEXT_IN
GTString 0,#Pname,64,16,85,16,txt$(51),#PLACETEXT_LEFT,8,playername$
GTString 0,#Cname,214,16,85,16,"Amiga",#PLACETEXT_LEFT,8,compname$
*gtscr.Screen = Peek.l (Addr Screen(0))
offy.b = *gtscr\WBorTop + *gtscr\_RastPort\TxHeight +1
fadeto{0,1}
Window 1,0,0,320,200,$1100,"Crazy Prefs -- version 2.5",1,2
WCls 3
WPointer 65
noise=28:Gosub makenoise
offx.b = WLeftOff
AttachGTList 0,1
fadeto{pl,1}
If ModOn.b=1 Then GTSetAttrs 0,#Music, #GTCB_Checked, True
If Fltr.b=True Then GTSetAttrs 0,#SndFilter, #GTCB_Checked, True
GTBevelBox 0,7+offx,1+offy,302,35,1
GTBevelBox 0,7+offx,39+offy,302,56,1
GTBevelBox 0,7+offx,98+offy,302,66,1
WJam 0
WColour 1,0
WLocate 28,104 : Print txt$(52)
WLocate 198,102 : Print txt$(53)
WColour 2,0
WLocate 138,43 : Print txt$(54)
WLocate 115,6 : Print txt$(55)
; --- Kick 2.00 compatible GTGetInteger and GTGetString commands
; ---
; --- GTGetStr GTList#, gadid (GTGetString replacement)
; ---
Function.s GTGetStr{lst.w, gdt.w}
*gad.Gadget = GTGadPtr(lst, gdt)
*si.StringInfo = *gad\SpecialInfo
a$= Peek$(*si\_Buffer)
Function Return a$
End Function
split=0
.prefloop
Repeat
ev.l = WaitEvent
If ev = #IDCMP_GADGETUP OR ev= #IDCMP_GADGETDOWN
noise=13:Gosub makenoise
If ev=$20
Select GadgetHit
Case #ScoreMX
scbtn=EventCode
If scbtn =0 Then maxpoints=50
If scbtn =1 Then maxpoints=100
If scbtn=2 Then maxpoints=150
If scbtn=3 Then maxpoints=200
If scbtn=4 Then maxpoints=300
Case #LoseWinMX
scoreon=EventCode
End Select
Else
Select GadgetHit
Case #ModString
newmod$=GTGetStr{0,51}
Gosub CheckMed
Case #BtnSave
compname$=GTGetStr{0,62}
playername$=GTGetStr{0,61}
Gosub savepref
split=1
Case #ModReq
Gosub LoadMed
Case #Music
If ModOn=1
ModOn=0
StopMed
music=0
Free MedModule 0
DetachGTList 0
GTDisable 0,#ModReq
GTDisable 0,#ModString
AttachGTList 0,1
Else
ModOn=1
ld$=pa$+"/"+fi$
LoadMedModule 0,ld$
music=1
Gosub MusicOn
DetachGTList 0
GTEnable 0,#ModReq
GTEnable 0,#ModString
AttachGTList 0,1
EndIf
Case #SndFilter
If Fltr=True
Fltr=False
Else
Fltr=True
EndIf
Gosub setflt
Case #BtnUse
split=1
compname$=GTGetStr{0,62}
playername$=GTGetStr{0,61}
End Select
EndIf
EndIf
FlushEvents
Until split
;If split=0 Then Goto prefloop
split=0
VWait
Use Window 0
fadeto{0,1}
DetachGTList 0
Free Window 1
Free GTList 0
Goto Playgame
.LoadMed
ld$=defmed$
newmod$=ASLFileRequest$(txt$(56),pa$,fi$,0,0,320,200)
.CheckMed
If newmod$<>""
If ReadFile(0,newmod$)
FileInput 0
A$ = Edit$(12) ; Read 12 bytes or upto a chr$(10)
CloseFile 0
Use Window 0
If Left$(A$,3)= "MMD" AND Right$(A$,1) = "4" ; OK, 4 channel MED
size.l=FileSize(newmod$) ;check mod length
If music=1 Then Gosub fademusic
Free MedModule 0 ;can old mod
VWait 10
chips.l=ChipFree ;check chip mem
If chips>size+5000 ;ok to load new mod
ld$=newmod$ ;so change name
defpa$=pa$
deffi$=fi$
If GadgetHit = #ModReq Then GTSetString 0,#ModString,ld$
Else ;short on chip mem!
A$=txt$(68)+" = "+Str$(chips)
B$=txt$(69)+" "+Str$(size+5000)+"|"+txt$(70)
Request A$,B$,txt$(61)
pa$=defpa$
fi$=deffi$
EndIf
ld$=pa$+"/"+fi$
VWait 10
LoadMedModule 0,ld$
music=1
Gosub MusicOn
Else ; not a 4 channel med!
Request txt$(65),txt$(67),txt$(61)
EndIf
Else ; can't even find it!
Request txt$(65),txt$(66),txt$(64)
EndIf
EndIf
Return
.LoadSounds
snderr.b=0
For i=0 To 33
Timeout(i)=0
Free Sound i
lsd$=snd$+sd$(i) ;now load the sounds
lnth.l=Exists(lsd$)
If lnth>0 AND ChipFree > lnth
If ReadFile(0,lsd$)
FileInput 0
temp$=Inkey$(12)
CloseFile 0
Use Window 0
;If Right$(temp$,4)="8SVX"
If Instr(temp$,"8SVX")
LoadSound i,lsd$
CacheClearU_
;Request "",Str$(Timeout(i)),"OK"
soundnumber.w=i
Gosub SoundDelay
Timeout(i)=delay.w
;Request "returned",Str$(Timeout(i)),"OK"
Else
snderr+1
EndIf
Else
snderr+1
EndIf
Else
snderr+1
EndIf
Next
If snderr>0 AND showerr=True
Format ""
Request "Crazy 8 sounds",Str$(snderr)+" sounds not loaded","OK"
EndIf
Return
.FinishSound ;wait until the sound is done
If hold>0
Repeat
VWait
Until hold=0
EndIf
Return
;determine the playing time of the samples
.SoundDelay
period.q=Peek.w(Addr Sound (soundnumber)+4) ;get the period from sound object
lngth.l=(Peek.w(Addr Sound (soundnumber)+6) AND $FFFF)*2 ;get the length from sound object
frequency.f = 3579440/period ;convert to true frequency
delay.w=lngth/(frequency/vrate) ;convert to playing time in VBlanks
delay+5 ;add a bit of padding for short samples
Return
.makenoise
If Timeout(noise)>0
SetMedMask 3
hold=Timeout(noise)
Sound noise,12
EndIf
Return
.fademusic
For i=64 To 0 Step -1
SetMedVolume i
VWait 2
Next
StopMed
SetMedVolume 64
Return
.MusicOn
If ModOn=1 Then StartMedModule 0
.setflt
If Fltr=False
Filter On
Else
Filter Off
EndIf
Return
.CompComplain ;complain in print and sound
complain=complain + 1 ;and set a new complaint so we
If complain>9 Then complain=1 ;don't say the same thing all the time
Gosub makenoise
Return
.CompNoise
Select complain ;select a noise
Case 1
noise=25
Case 2
noise=30
Case 3
noise=24
Case 4
noise=29
Case 5
noise=16
Case 6
noise=31
Case 7
noise=1
Case 8
noise=7
Case 9
noise=32
End Select
Return
.savepref
If WriteFile (0,"data/8prefs") ;open pref file
FileOutput 0
NPrint compname$ ;computer's name
NPrint playername$ ;player's name
NPrint Fltr ;audio filter on or off
NPrint pa$ ;default path
NPrint fi$ ;mod name
NPrint scbtn ;mx scorebutton selected
NPrint maxpoints ;default top score
NPrint scoreon ;add points to looser if 0
NPrint pl ;save the palette
NPrint ModOn ;use music if 1
NPrint snd$
CloseFile 0
WindowOutput 1
Else
Request txt$(60),txt$(71),txt$(64)
EndIf
Return
.loadpref
If ReadFile (0,"data/8prefs") ;open pref file
FileInput 0
compname$=Edit$(15) ;computer's name
playername$=Edit$(15) ;player's name
Fltr.b=Edit(6) ;audio filter on or off
pa$=Edit$(200) ;default path
fi$=Edit$(200)
scbtn.b=Edit(6) ;mx scorebutton selected
maxpoints.w=Edit(6) ;default top score
scoreon.b=Edit(6) ;add points to looser if 0
pl.b=Edit(6) ;get the palette
ModOn.b=Edit(6) ;use music if 1
snd$=Edit$(256) ;sample path
CloseFile 0
WindowInput 0
Else ;Use Defaults
compname$="Amiga" ;computer's name
playername$=txt$(57) ;player's name
Fltr.b=False ;audio filter on or off
pa$="data/Mods" ;default path
fi$="Med.Moonshine" ;default module name
scbtn.b=3 ;mx scorebutton selected
maxpoints.w=200 ;default top score
scoreon.b=0 ;add points to looser if 0
ModOn.b=1
pl.b=1
snd$="sounds/original/"
EndIf
defpa$=pa$
deffi$=fi$
Return
.getSoundPath ;select the Samples directory with a listview
dirs.w=0 ;number of entries found
showme.w=0 ;the current selection
drnow$=UnLeft$(Mid$(snd$,8),1)
drawer$=ourpath$+"/sounds/"
ChDir drawer$ ; CD to the sounds/ directory
ResetList sndDrawers()
While MoreEntries ; check if there's any more entries
File_Name$=EntryName$ ; get its name
If EntryDIR ; check if its a directory
If File_Name$=drnow$
showme=dirs
EndIf
dirs+1 ;yes, so increase the directory count
If AddItem(sndDrawers())
sndDrawers()\string=" "+File_Name$
EndIf
EndIf
Wend
GTTags #GTLV_ShowSelected,0,#GTLV_MakeVisible,showme
GTListView 2,51,0,0,290,170,"",0,sndDrawers(),showme,0
AddIDCMP #INTUITICKS
AddIDCMP #MOUSEMOVE
VWait
CacheClearU_
Window 2,10,20,300,178,$1000," Select a Sample Set:",1,2
SubIDCMP #INTUITICKS|#MOUSEMOVE
MenusOff
AttachGTList 2,2
Repeat
ev.l=WaitEvent
If ev=$40
showme=EventCode
EndIf
Until ev=$40 AND EventWindow=2
ResetList sndDrawers()
For i = 0 To showme
dummy=NextItem(sndDrawers())
Next
newsnd$=Mid$(sndDrawers()\string,2)
newsnd$="sounds/"+newsnd$+"/"
DetachGTList 2
Free GTList 2
Free Window 2
Use Window 0
ClearList sndDrawers()
ChDir ourpath$
Return
.GetLocale
If ReadFile (0,"locale/C8.LOCALE")
FileInput 0
t$=Edit$(180)
If Left$(t$,2)<>"C8" Then Goto badlocale
i=0
getAnother
t$=Edit$(100)
txt$(i)=t$
i+1
If i < 75
If NOT Eof(0)
Goto getAnother
Else
Goto badlocale
EndIf
Else
CloseFile 0
WindowInput 0
EndIf
Return
EndIf
badlocale
Request "Locale Error","Can't load Locale file|Please read the docs","Darn!"
End
.ScoreTable
If Exists("c8.scores") ;read in the saved scores, if any
If ReadFile(0,"c8.scores")
FileInput 0
entries.w=Edit(8)
i=1
While NOT Eof(0)
scorename$(i)=Edit$(30)
gamesplayed(i)=Edit(6)
gameswon(i)=Edit(6)
i+1
Wend
CloseFile 0
WindowInput 0
Use Window 0
EndIf
Else
entries=2
scorename$(1)=playername$
scorename$(2)=compname$
EndIf
;fix list to add current names
temp$=playername$
exc.b=1
Gosub addname
temp$= compname$
exc=2
Gosub addname
;fix scores
If gamedone=True
For i=1 To entries
If scorename$(i)=compname$
gamesplayed(i)+1
If cwon=True
gameswon(i)+1
EndIf
EndIf
If scorename$(i)=playername$
gamesplayed(i)+1
If pwon=True
gameswon(i)+1
EndIf
EndIf
Next
EndIf
;figure % and sort arrays here ----
For i = 1 To entries
If gamesplayed(i)
won1.q=(gameswon(i)/gamesplayed(i))*100
winpct(i)=Int(won1)
Else
winpct(i)=0
EndIf
Next
Repeat ;sort by number of games played first
dummy=0
For i = 1 To entries-1
If gamesplayed(i)<gamesplayed(i+1)
Gosub switchem
EndIf
Next
Until dummy=0
Repeat ;now sort by winning %
dummy=0
For i = 1 To entries-1
If winpct(i)<winpct(i+1) AND gamesplayed(i)=gamesplayed(i+1)
Gosub switchem
EndIf
Next
Until dummy=0
If gamedone=True ;save scores to disk
If WriteFile (0,"c8.scores")
FileOutput 0
If entries>30 Then entries=30
NPrint entries
For i = 1 To entries
NPrint scorename$(i)
NPrint gamesplayed(i)
NPrint gameswon(i)
Next
CloseFile 0
WindowOutput 0
Else
Request "Disk Error","Can't save scores!","OK"
EndIf
EndIf
gamedone=False
;now we'll make a listview to show the scores
Dim List MyList.scores(entries + 1)
Format "##0"
For i = 1 To entries
If AddItem(MyList())
temp$=LSet$(scorename$(i),14)
lis$=" "+temp$+Str$(gamesplayed(i))+" "+Str$(gameswon(i))+" "+Str$(winpct(i))+"%"
MyList()\string = lis$
EndIf
Next
GTListView 2,51,0,0,290,170,"",0,MyList(),0,0
AddIDCMP #INTUITICKS
AddIDCMP #MOUSEMOVE
VWait
CacheClearU_
Window 2,10,20,300,178,$1000|$8," Player Games Won",1,2
SubIDCMP #INTUITICKS|#MOUSEMOVE
MenusOff
AttachGTList 2,2
FlushEvents
Repeat
ev.l=WaitEvent
Until ev=$200 OR ev=$40
DetachGTList 2
Free GTList 2
Free Window 2
Use Window 0
FlushEvents
Return
switchem
Exchange scorename$(i),scorename$(i+1)
Exchange gamesplayed(i),gamesplayed(i+1)
Exchange gameswon(i),gameswon(i+1)
Exchange winpct(i),winpct(i+1)
dummy=1
Return
.addname
gotim.b=False
For i = 1 To entries
If temp$=scorename$(i)
i=entries
gotim=True
EndIf
Next
If gotim=False
entries+1
scorename$(entries)=temp$
Exchange scorename$(entries),scorename$(exc)
Exchange gamesplayed(entries),gamesplayed(exc)
Exchange gameswon(entries),gameswon(exc)
EndIf
Return
.PrintReq ;this prints Continue & Exit on quit requestor
ShapesBitMap 64,3 ;dummy bitmap so we can draw on a shape
FNSOutput 3,1 ;send the print to it
FNSPrint 1,31,25,txt$(73),#centred,1 ;Continue
FNSPrint 1,31,24,txt$(73),#centred,1
FNSPrint 1,30,25,txt$(73),#centred,1
FNSPrint 1,30,24,txt$(73),#centred,7
FNSPrint 1,265,25,txt$(59),#centred,1 ;Quit
FNSPrint 1,265,24,txt$(59),#centred,1
FNSPrint 1,264,25,txt$(59),#centred,1
FNSPrint 1,264,24,txt$(59),#centred,7
ShapesBitMap 53,3 ;now the pref-menu-play requestor
FNSOutput 3,1 ;send the print to it
FNSPrint 1,43,27,txt$(74),#centred,1 ;Prefs
FNSPrint 1,43,26,txt$(74),#centred,1
FNSPrint 1,42,27,txt$(74),#centred,1
FNSPrint 1,42,26,txt$(74),#centred,7
FNSPrint 1,142,27,txt$(72),#centred,1 ;Menu
FNSPrint 1,142,26,txt$(72),#centred,1
FNSPrint 1,141,27,txt$(72),#centred,1
FNSPrint 1,141,26,txt$(72),#centred,7
FNSPrint 1,243,27,txt$(58),#centred,1 ;Play
FNSPrint 1,243,26,txt$(58),#centred,1
FNSPrint 1,242,27,txt$(58),#centred,1
FNSPrint 1,242,26,txt$(58),#centred,7
Return
.FixMode
If ntsSys=True ;original screen mode
ForceNTSC
Else
ForcePAL
EndIf
Return
INCDIR ""
Even
;Incbin our font into the compiled file to save effort later
font_dat: IncBin "C8.FNS"